package com.bckj.freshnow.order.trade.execution.create;

import cn.hutool.core.lang.Assert;
import com.bckj.fastboot.core.execution.Execution;
import com.bckj.fastboot.core.execution.ExecutionContext;
import com.bckj.freshnow.order.model.CreateTradeOrderRequest;
import com.bckj.freshnow.order.trade.fsm.TradeOrderContext;
import org.springframework.stereotype.Component;

@Component
public class CreateTradeOrderCheckRequestExecution implements Execution {

    @Override
    public void execute(ExecutionContext context) {
        var ctx = (TradeOrderContext) context;
        CreateTradeOrderRequest request = (CreateTradeOrderRequest) ctx.getRequest();
        Assert.notEmpty(request.getItemList(), "订单商品不能为空");
        request.getItemList().forEach(item -> {
            Assert.notEmpty(item.getSkuCode(), "订单商品skuCode不能为空");
            Assert.notNull(item.getQuantity(), "订单商品数量不能为空");
        });
    }
}
